﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using T0yK4T.Data;
//using MongoDB.Driver;
//using MongoDB.Driver.Builders;
//using MongoDB.Bson;
//using System.Text.RegularExpressions;

//namespace ToyChat.Core
//{
//    public class MongoAdapter<T> : IDataAdapter<T> where T : class, new()
//    {
//        private MongoDatabase db;
//        private MongoCollection collection;
//        private IEnumerable<IDataProperty<T>> indexFields;
//        private Type tType = typeof(T);
//        private IDataSerializer<T> serializer = new DataSerializer<T>();

//        public MongoAdapter(MongoDatabase database, IEnumerable<IDataProperty<T>> indexFields)
//        {
//            this.db = database;
//            this.collection = this.db.GetCollection<T>(tType.FullName);
//            this.indexFields = indexFields;
//            foreach (IDataProperty<T> prop in this.indexFields)
//                this.collection.CreateIndex(new IndexKeysDocument(prop.PropertyName, 1), new IndexOptionsDocument(false));
//        }

//        #region IDataAdapter<T> Members

//        public void Store(T value)
//        {
//            IEnumerable<IDataProperty<T>> val = this.serializer.Serialize(value);
//            //IMongoQuery q = Query.Null;
//            //foreach (IDataProperty<T> key in val.Where(p => indexFields.Any(i => i.PropertyName == p.PropertyName)))
//            //    q = Query.And(Query.EQ(key.PropertyName, BsonValue.Create(key.Value)), q);
//            T one = this.FindOne(val.Where(p => this.indexFields.Any(i => i.PropertyName == p.PropertyName)));
//            if (one != null)
//                this.collection.Update(query, new UpdateDocument(val.Select<IDataProperty<T>, BsonElement>(p => new BsonElement(p.PropertyName, BsonValue.Create(p.Value)))));
//        }

//        public T GetFirst()
//        {
//            throw new NotImplementedException();
//        }

//        public IEnumerable<T> GetAll()
//        {
//            throw new NotImplementedException();
//        }

//        public T FindOne(IDataProperty<T> property)
//        {
//            throw new NotImplementedException();
//        }

//        public T FindOne(IEnumerable<IDataProperty<T>> properties)
//        {
//            throw new NotImplementedException();
//        }

//        //public T FindOne(params DataProperty<T>[] properties)
//        //{
//        //    if (properties != null)
//        //        return this.FindOne(properties);
//        //}

//        public void Update(T value)
//        {
//            throw new NotImplementedException();
//        }

//        public IEnumerable<T> Find(IDataProperty<T> property)
//        {
//            throw new NotImplementedException();
//        }

//        public void Delete(IDataProperty<T> property)
//        {
//            throw new NotImplementedException();
//        }

//        public IEnumerable<T> Find(IEnumerable<IDataProperty<T>> properties, BooleanOperator op)
//        {
//            throw new NotImplementedException();
//        }

//        public void Delete(IEnumerable<IDataProperty<T>> properties, BooleanOperator op)
//        {
//            throw new NotImplementedException();
//        }

//        public IEnumerable<T> Find(string KeyName, Regex searchPattern)
//        {
//            throw new NotImplementedException();
//        }

//        public void Delete(string keyName, Regex searchPattern)
//        {
//            throw new NotImplementedException();
//        }

//        public IEnumerable<T> Find(BooleanOperator op, params KeyValuePair<string, Regex>[] matchFields)
//        {
//            throw new NotImplementedException();
//        }

//        public void Delete(BooleanOperator op, params KeyValuePair<string, Regex>[] matchFields)
//        {
//            throw new NotImplementedException();
//        }

//        public IEnumerable<T2> Distinct<T2>(string key)
//        {
//            throw new NotImplementedException();
//        }

//        public IEnumerable<T2> Distinct<T2>(string key, BooleanOperator op, params KeyValuePair<string, Regex>[] matchFields)
//        {
//            throw new NotImplementedException();
//        }

//        public int Count(BooleanOperator op, params KeyValuePair<string, Regex>[] matchFields)
//        {
//            throw new NotImplementedException();
//        }

//        #endregion
//    }
//}
